package uet;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FeaturesCombiner {
	public static void main(String[] args) {
		
		String inpFile1 = "RITE2_JA_dev_unittest_BLEU1.txt";
		String inpFile2 = "Data/features4_train.txt";
		String outFile = "Data/features5_train.txt";
		/*
		String tmp1 = "6 #10-0";
		String tmp2 = "1 1:0.84 2:0.6875 3:0.7 4:0.852941176471  #10-0";
		*/
	    try {
	    	Scanner scanner1 = new Scanner(new File(inpFile1));
	    	Scanner scanner2 = new Scanner(new File(inpFile2));
	    	
	    	PrintWriter log = new PrintWriter(new BufferedWriter(
	                new FileWriter(outFile)));
	    	
	        ArrayList<String> str1 = new ArrayList<String>();
	        ArrayList<String> str2 = new ArrayList<String>();
	        
	        String tmp = "";
	        
	        while(scanner1.hasNext()){
	        	tmp = scanner1.nextLine();
	        	if(!tmp.equals("")){
	        		str1.add(tmp);
	        	}
	        }
	        
	        while(scanner2.hasNext()){
	        	tmp = scanner2.nextLine();
	        	if(!tmp.equals("")){
	        		str2.add(tmp);
	        	}
	        }
	        scanner1.close();
	        scanner2.close();
	        
	        for(int i = 0; i < str1.size(); i++){
	        	for(int j = 0; j < str2.size(); j++){
	        		
	        		String tmp1 = str1.get(i);
	        		String tmp2 = str2.get(j);
	        		
	        		int index1 = tmp1.indexOf("#");
	        		int index2 = tmp2.indexOf("#");
	        		
	        		if((index1 > -1) && (index2 > -1)){
	        			String id1 = tmp1.substring(index1);
		        		String id2 = tmp2.substring(index2);
		        		
		        		if(id1.equals(id2)){
		        			tmp = tmp2.substring(0, index2-1) + "100:" + tmp1.substring(0, index1-1) 
		        			+ "  " + tmp2.substring(index2);
		        		
		        			log.println(tmp);        		        		
		        		}
	        		}
	        		
	        	}
	    	}
	        log.close();
	 	}
	    catch (Exception e) { //catch file-related errors
	        e.printStackTrace();
	    }

	}
}
